package com.xjz.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * ClassName: JsonConfig
 * Package: com.xjz.config
 * Description:
 *
 * @Author 许小健
 * @Create 2025/8/2 11:00
 * @Version 1.0
 */

@Configuration
public class JsonConfig {

    /**
     * 添加Long转json精度丢失
     * @param builder
     * @return
     */

    @Bean
    public ObjectMapper customJacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        SimpleModule module = new SimpleModule();
        module.addSerializer(Long.class, ToStringSerializer.instance);
        module.addSerializer(Long.TYPE, ToStringSerializer.instance);
        objectMapper.registerModule(module);
        return objectMapper;

    }
}
